package com.example.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class ConnUtils {
    public static  Connection getConn(){
        Connection conn =null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/news",
                    "root",
                    "sa123"
            );
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return  conn;
    }
    public static void main(String[] args) {
    Connection conn =ConnUtils.getConn();
    if (conn!=null){
        System.out.println("连接成功");
    }else {
        System.out.println("链接失败");
    };

    }
}
